package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.UserDao;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

//为自定义权限类提供服务
@Service(interfaceClass = UserService.class)
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    //通过用户名查询 登录验证
    public User findByUsername(String username) {

        User user = userDao.findByUsername(username);
        //没有该用户名,登陆失败
        if (user == null) {
            return null;
        }

        Integer userId = user.getId();

        //封装基本信息,角色,权限的User对象
        return userDao.findAllsByUserId(userId);

    }
}
